<template>
  <el-dialog
    title="编辑积分"
    :visible="value"
    width="700px"
    custom-class="dialog-box"
    @close="onClose"
    @open="onOpen"
    :close-on-click-modal="false"
    :append-to-body="true"
  >
    <el-form
      ref="form"
      :model="form"
      :rules="rules"
      label-width="160px"
      @submit.native.prevent="onSubmit"
    >
      <el-row>
        <el-col :span="20">
          <el-form-item label="选择类型：">
            <el-radio-group v-model="form.type">
              <el-radio :label="1">增加</el-radio>
              <el-radio :label="2">扣减</el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="20">
          <el-form-item label="变动积分：" prop="num">
            <el-input v-model.number="form.num" type="number"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="20">
          <el-form-item label="备注：">
            <el-input v-model="form.desc"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-button v-show="false" :loading="btnLoading" native-type="submit">提交</el-button>
    </el-form>
    <span slot="footer">
      <el-button type="primary" :loading="btnLoading" @click="onSubmit">确 定</el-button>
    </span>
  </el-dialog>
</template>
<script>
import validate from '@/_js/validate'
export default {
  props: ["value", "curItem"],
  data() {
    return {
      btnLoading: false,
      form: {
        type: 1,
        num:'',
        desc:'',
        patientId:''
      },
      name: "",
      rules: {
        num: [{ required: true, message: "此项必填", trigger: "blur" },{validator: validate.integerNumber, message: "请输入正确积分", trigger: "blur" }]
      },
        // ]
      familyList: [],
      tableList: []
    };
  },
  mounted() {
    this.onOpen();
  },
  methods: {
    onSubmit() {
      let th = this;
      th.form.patientId=th.curItem.patientId;
      let j={}
      Object.assign(j,th.form)
      th.$api.updateRecord(j).then(res=>{
          if (res.executed) {
            th.$message.success("保存成功");
            //获取对应的科室名称
            th.$emit("success");
            th.onClose();
            th.btnLoading = false;
          } else {
            th.$message.error(res.message);
            th.btnLoading = false;
          }
      })
    },
    onOpen() {
      let th=this;
      th.form.desc=''
    },
    onClose() {
      let th = this;
      th.$refs["form"].resetFields();
      th.$emit("input", false);
    }
  }
};
</script>
